package chapter1.fundamentals.exercise;

import java.math.BigInteger;

/**
 * @author quanlinlin on 2018/10/26 12:34.
 * @version 1.0
 */
public class E_19 {

    public static void main(String[] args) {
        getResult();
        //fib(100);
    }

    private static void getResult() {
        int n = 20000;
        BigInteger[] a = new BigInteger[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = BigInteger.valueOf(0);
        }
        for (int N = 0; N < n; N++) {
            System.out.println(N + " " + F(N, a));
        }
    }

    private static BigInteger F(int n, BigInteger[] a) {
        if (n == 0) {
            return BigInteger.valueOf(0);
        }
        if (n == 1) {
            return BigInteger.valueOf(1);
        }
        if (a[n].intValue() != 0) {
            return a[n];
        } else {
            return a[n] = F(n - 1, a).add(F(n - 2, a));
        }

        //return F(n - 1, a).add(F(n - 2, a));
    }

    public static boolean equal(BigInteger v) {
        return false;
    }

    public static long fib(int n) {
        long a = 0;
        long b = 1;

        long c;
        for (int i = 1; i < 100; i++) {
            c = b;
            b = a + b;
            a = c;
            System.out.println(i + " : " + a);
        }
        return b;
    }
}
